package edu.dublbo.app.generator.entity;

import edu.dublbo.app.generator.util.StrUtils;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 * @author DubLBo
 * @since 2020-09-07 15:59
 * i believe i can i do
 */
@Getter
@Setter
public class TBasicModelDetail implements Serializable {
    private static final long serialVersionUID = 238650092367164538L;
    // 主键
    private String id;
    // 所属模型ID
    private String modelId;
    // 属性名称
    private String propertyName;
    // 属性类型ID
    private int propertyTypeId;
    // 备注，注释
    private String remark;
    // 字段名，根据属性名自动生成
    private String columnName;
    // 字段类型ID
    private int columnTypeId;
    // 字段长度
    private Integer columnLength;
    // 排序，默认为900
    private Integer sortNo;
    // 不可删除标记
    private Integer inherentFlag;
    // 创建人
    private String createUser;
    // 创建时间
    private Date createTime;
    // 最后修改人
    private String modifyUser;
    // 最后修改时间
    private Date modifyTime;
    // 是否删除（1：是，0：否）
    private Integer deleteFlag;

    // 属性类型名
    private String proType;
    // 属性全限定类型名（带包路径）
    private String qualifiedProType;

    // 字段类型名
    private String colType;
    // 字段默认长度
    private Integer defaultColLen;
    // 字段类型展示：字段类型 + 长度
    private String colTypeShow;

    public TBasicModelDetail() {}

    public TBasicModelDetail(String propertyName,
                             int propertyTypeId,
                             String columnName,
                             int columnTypeId,
                             Integer columnLength,
                             String remark,
                             Integer deleteFlag,
                             String createUser,
                             String modifyUser,
                             int inherentFlag,
                             int sortNo) {
        this.propertyName = propertyName;
        this.propertyTypeId = propertyTypeId;
        this.columnName = columnName;
        this.columnTypeId = columnTypeId;
        this.columnLength = columnLength;
        this.remark = remark;
        this.deleteFlag = deleteFlag;
        this.createUser = createUser;
        this.modifyUser = modifyUser;
        this.inherentFlag = inherentFlag;
        this.sortNo = sortNo;
    }

    public static boolean checkValid(TBasicModelDetail de) {
        return de != null
                && !StrUtils.isBlank(de.getModelId())
                && !StrUtils.isBlank(de.getPropertyName())
                && de.getPropertyTypeId() > 0
                && !StrUtils.isBlank(de.getColumnName())
                && de.getColumnTypeId() > 0
                && !StrUtils.isBlank(de.getRemark());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TBasicModelDetail that = (TBasicModelDetail) o;
        return Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        return result;
    }

    @Override
    public String toString() {
        return "TBasicModelDetail{" +
                "id='" + id + '\'' +
                ", modelId='" + modelId + '\'' +
                ", propertyName='" + propertyName + '\'' +
                ", propertyTypeId=" + propertyTypeId +
                ", remark='" + remark + '\'' +
                ", columnName='" + columnName + '\'' +
                ", columnTypeId=" + columnTypeId +
                ", columnLength=" + columnLength +
                '}';
    }
}
